<?php
// +----------------------------------------------------------------------
// | Exquisite
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Blovex4\Controller;

/**
 * 前端展示效果图控制器
 *
 * @author derek <693472824@qq.com>
 */
class BannerController extends AdminController {

    /**
     * 效果图
     * @author derek <693472824@qq.com>
     */
    public function index(){
    
        $map = array();
        
        $name = I('name');
    
        if(!empty($name)){
            $map['name'] = array('like', '%'.$name.'%');
        }
    
        $model = D('BannerView');
    
        $list = $this->lists($model, $map, 'banner_id DESC');
    
        $this->assign('name', $name);
        $this->assign('list', $list);
        $this->display();
    }
    

    /**
     * 新增/修改风格
     * @param integer $style_id 风格ID
     * @author derek <693472824@qq.com>
     */
    public function editAction() {
        
        $bannerID = I('banner_id');
        $bannerLogic = D('Banner', 'Logic');
        
        if (!empty($bannerID)) {
            
            $bannerModel = D('BannerView')->where(array('banner_id'=>$bannerID))->find();
            
            if(empty($bannerModel)) {
                
                $this->error('获取数据失败', U('index'));
            }else{
                
                $this->assign('bannerModel', $bannerModel);
            }
        }
        
        $this->assign('fileSize', C('UPLOAD_PICTURE_CONFIG.maxSize'));
        $this->display();
    }

    /**
     * 保存手机前端效果图
     * @author derek <lixm@my818.com>
     */
    public function saveAction() {
    
        $bannerLogic = D('Banner', 'Logic');
        
        $result = $bannerLogic->saveAction();
    
        if ($result === false) {

            $this->error('操作失败' . $bannerLogic->getError());
        } else {
            
            $this->success('操作成功', U('index'));
        }
    }

    /**
     * 手机前端效果图删除
     * @author derek <693472824@qq.com>
     */
    public function del() {
        
        $bannerID = I('banner_id');
        
        if (empty($bannerID)) {
            $this->error('参数错误');
        }
        
        $result = M('Banner')->delete($bannerID);
        
        if ($result === false) {

            $this->error('操作失败', U('index'));
        } else {
            
            $this->success('操作成功！', U('index'));
        }
    }
    
}